import ajax from '../utils/axios'

export async function getClassificationList(params) {
  const res = await ajax.post(`/api/classification/list`, params)
  return res.data.data
}

export async function delClassification(id) {
  const res = await ajax.post(`/api/classification/delete?ids=${id}`)
  return res.data.data
}

export async function addClassification(params) {
  const res = await ajax.post(`/api/classification/create`, params)
  return res.data.data
}

export async function updateClassification(params) {
  const res = await ajax.post(`/api/classification/update`, params)
  return res.data.data
}

export async function getNormsList(params) {
  const { page, pageSize } = params
  const res = await ajax.post(`/api/norms/list`, params)
  return res.data.data
}

export async function deleteNorms(id) {
  const res = await ajax.delete(`/api/norms/delete?ids=${id}`)
  return res.data.data
}

export async function getGoodsList(params) {
  const res = await ajax.post(`/api/goods/list`, params)
  return res.data.data
}

export async function getRecommendGoodslist(params) {
  const res = await ajax.get(`/api/goods/getRecommendGoodslist`, { params })
  return res.data.data
}

export async function getGoodsDetail(id) {
  const res = await ajax.get(`/api/goods/detail?id=${id}`)
  return res.data.data
}

export async function deleteGoods(id) {
  const res = await ajax.post(`/api/goods/delete?ids=${id}`)
  return res.data.data
}

export async function createGoods(params) {
  const res = await ajax.post(`/api/goods/create`, params)
  return res.data.data
}

export async function editGoods(params) {
  const res = await ajax.post(`/api/goods/update`, params)
  return res.data.data
}

export async function createdGoodsNorms(params) {
  const res = await ajax.post(`/api/norms/create`, params)
  return res.data.data
}

export async function editGoodsNorms(params) {
  const res = await ajax.post(`/api/norms/update`, params)
  return res.data.data
}

export async function scanGoods(params) {
  const { goodsId, userId } = params
  const res = await ajax.post(
    `/api/goods/scanGoods?goodsId=${goodsId}&userId=${userId}`
  )
  return res.data.data
}

// 收藏商品
export async function wishGoods(params) {
  const { goodsId, userId } = params
  const res = await ajax.post(
    `/api/goods/wishGoods?goodsId=${goodsId}&userId=${userId}`
  )
  return res.data.data
}

// 取消收藏
export async function cancelWishGoods(params) {
  const { goodsId, userId } = params
  const res = await ajax.post(
    `/api/goods/cancelWishGoods?goodsId=${goodsId}&userId=${userId}`
  )
  return res.data.data
}

// 获取商品是否被用户收藏，0否 1是
export async function getWishGoodsFlag(params) {
  const { goodsId, userId } = params
  const res = await ajax.post(
    `/api/goods/getWishGoodsFlag?goodsId=${goodsId}&userId=${userId}`
  )
  return res.data.data
}
